import Vue from 'vue';
import Vuex from 'vuex';
Vue.use(Vuex);

const store = new Vuex.Store({
	state: {
		isAlreadyLogin: false,
		requestOption: undefined,
		client: undefined,
		jl: undefined,
		amount: undefined,
		dz: undefined,
		zj: undefined,
		zjgs: undefined,
		location: undefined,
		locationFlg: false,
		position: undefined
	},
	mutations: {
		submitClient(state, client) {
			state.client = client;
		},
		setPosition(state, position) {
			state.position = position;
		},
		setLocation(state, location) {
			if (location && location.provice) {
				state.position = {
					jd: location.provice.lng,
					wd: location.provice.lat
				}
			}
			
			if (location && location.city) {
				state.position = {
					jd: location.city.lng,
					wd: location.city.lat
				}
			}
			state.location = location;
			state.locationFlg = true;
		},
		removeLocation(state) {
			state.location = undefined;
			state.locationFlg = false;
		},
		submitZjgs(state, zjgs) {
			state.zjgs = zjgs;
		},
		submitZj(state, zj) {
			state.zj = zj;
		},
		submitDz(state, dz) {
			state.dz = dz;
		},
		submitJl(state, jiaolian) {
			state.jl = jiaolian;
		},
		submitAmount(state, amount) {
			state.amount = amount;
		},
		loginSuccess(state, autor) {
			state.isAlreadyLogin = true;
			state.client = autor.client;
			state.zj = autor.azj;
			state.dz = autor.adz;
			state.jl = autor.ajiaolian;
			if (autor.azjgs) {
				state.zjgs = autor.azjgs;
			}
			state.amount = autor.amount;
			if (state.requestOption) {
				state.requestOption.header["Cookie"] = "JSESSIONID="+state.sessionId;
				uni.request(state.requestOption);
				state.requestOption = undefined;
			}
		},
		loginOut(state) {
			state.isAlreadyLogin = false;
		}
	}
});
export default store;